package tech.runchen.gz5055.oms.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tech.runchen.gz5055.oms.common.utils.PageInfo;
import tech.runchen.gz5055.oms.common.utils.Query;
import tech.runchen.gz5055.oms.modules.system.entity.SysLogininforEntity;
import tech.runchen.gz5055.oms.modules.system.mapper.SysLogininforMapper;
import tech.runchen.gz5055.oms.modules.system.service.ISysLogininforService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzj
 * @since 2023-03-07
 */
@Service
public class SysLogininforServiceImpl extends ServiceImpl<SysLogininforMapper, SysLogininforEntity> implements ISysLogininforService {

    @Override
    public PageInfo queryPage(Map<String, Object> params) {

        String userName = (String) params.get("userName");
        Object status = params.get("status");

        IPage<SysLogininforEntity> page = this.page(
                new Query<SysLogininforEntity>().getPage(params),
                new QueryWrapper<SysLogininforEntity>()
                        .like(Objects.nonNull(userName), "user_name", userName)
                        .eq(Objects.nonNull(status), "status", status)
                        .orderByDesc("id")
        );

        return new PageInfo(page);
    }

    @Override
    public List<SysLogininforEntity> querySelect(Map<String, Object> params) {

        String userName = (String) params.get("userName");
        Object status = params.get("status");

        List<SysLogininforEntity> list = this.list(new QueryWrapper<SysLogininforEntity>()
                .like(Objects.nonNull(userName), "user_name", userName)
                .eq(Objects.nonNull(status), "status", status)
                .orderByDesc("id")
        );
        return list;
    }

    @Override
    public boolean saveLogininfor(SysLogininforEntity logininfor) {
        return this.save(logininfor);
    }

    @Override
    public boolean updateLogininfor(SysLogininforEntity logininfor) {
        return this.updateById(logininfor);
    }

    @Override
    public void deleteBatch(Long[] logininforIds) {
        baseMapper.deleteBatchIds(Arrays.asList(logininforIds));
    }

}
